package com.itdfq.loginuser.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

import java.nio.charset.StandardCharsets;

/**
 * @Author: GodChin
 * @Date: 2021/8/23 14:21
 * @Blog: itdfq.com
 * @QQ: 909256107
 * @Description:
 */
public class PasswordUtils {


    private static final String PPRIVATEKEY="MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMWbHfeJ+ruCfF/K9plS2pI33uHoRBAK3T0/8WHfGvtjt+RFyNcG9Ncq1TFx+nzxO5GhfxqLtFeAv6xr2JCJxcmNRGKpjbXaDWV6grCYg8zx5yb805ul2ovWHiB2N1rvpyMmU4yyA9puX/3A4sdZDu8URzKIGa0/I/oO2X/WBGTpAgMBAAECgYB82wrvOnZ7ffIaEMMJk6lZFAY3FSvUOxkZN0rMPUzuJE6v5EwHWXTgc0brjAnqYf3ygWkvG7CiTU5OooHeqb6XAnlF+muLkoqnALunkfvEdFVlJmULujIi3JCki+JVFOnmzi3aovXsFFi8S84X8lvRlvDXxrEm6NZH2xJPFhITAQJBAPlH3V32eD26kqg50kBBTP7nUGB5sDQQd7Ye0t3LybJ5FC45KwsLH4obVGk8EyJ6pRKavcqs57DYwSYq6kSjSGECQQDK7q0GMSdN+xzjau/a5ox8dL3HLKJU+Y7LbwDCZfXUG1i6lfWOnDNJ+SXTDvgEYYiF0oWSIymPRpATgVkPX0mJAkAvh9RdpjEnE/wCt4OvXMQhllltC8bdJoas4xOx1rmOnieK6LucT3KkErH1ns7HNDtlYLvveSh0P+AUNvqUO84BAkEAoFM6zZaN5/UJmL6GqxnUSgttV+tygNH9N8oF/o/RTPch/Z+2Nio/9yRo9rtvxP5NfvSY5KD1F6X29AIQG637iQJAbf5EVHWcwKxGWLq3q6RxSA0KuDi7wfCqE1rtY6noXxVh3jVXlxWLx6PoCV5ena4cbzaKoCQuXS/rwmsmhRjGoQ==";
    private static final String PPUBLICKEY="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFmx33ifq7gnxfyvaZUtqSN97h6EQQCt09P/Fh3xr7Y7fkRcjXBvTXKtUxcfp88TuRoX8ai7RXgL+sa9iQicXJjURiqY212g1leoKwmIPM8ecm/NObpdqL1h4gdjda76cjJlOMsgPabl/9wOLHWQ7vFEcyiBmtPyP6Dtl/1gRk6QIDAQAB";

    /**
     * 解密
     * @param password
     * @return
     */
    public static String getPassword(String password){
        RSA rsa = new RSA(PPRIVATEKEY,PPUBLICKEY);
        byte[] decrypt = rsa.decrypt(password, KeyType.PrivateKey);
        return StrUtil.str(decrypt, StandardCharsets.UTF_8);
    }

    /**
     * 加密
     * @param password
     * @return
     */
   public static String setPassword(String password){
       RSA rsa = new RSA(PPRIVATEKEY,PPUBLICKEY);
       String ceshi = rsa.encryptBase64(password, KeyType.PublicKey);
       return ceshi;
   }

}
